AC_INIT(LibBancoPG, 2.0.1, alcione.sombra@gmail.com, libbancopg, http://www.alcionesytes.net)
AC_PREREQ([2.50])
AC_CONFIG_AUX_DIR([.])
AM_INIT_AUTOMAKE([1.11 gnu -Wall dist-xz])
AC_CONFIG_MACRO_DIR([m4])
m4_pushdef([AC_INCLUDES_DEFAULT], [$1])
AC_COPYRIGHT([Alcione Ferreira])
AC_REVISION([$Revision: 2.0.1 $])

AC_CONFIG_HEADERS([src/configbpg.h])
LT_INIT([static])
AC_PROG_CXX
AC_PROG_LD
AC_LANG([C++])

######################################################################
# DOXYGEN SUPPORT
######################################################################

DX_HTML_FEATURE(ON)
DX_CHM_FEATURE(OFF)
DX_CHI_FEATURE(OFF)
DX_MAN_FEATURE(ON)
DX_RTF_FEATURE(OFF)
DX_XML_FEATURE(OFF)
DX_PDF_FEATURE(ON)
DX_PS_FEATURE(ON)

DX_INIT_DOXYGEN([$PACKAGE_NAME],[doxygen.cfg],[doc])

######################################################################

AM_PROG_LIBTOOL
AC_PREFIX_DEFAULT([/usr])
# --with-dinamico
AC_ARG_WITH(dinamico,
  [AS_HELP_STRING([--with-dinamico],[Compilação Dinâmica])
  ],
  [ ],
  [with_dinamico=yes]
)
AC_ARG_WITH(pg_config, [	--with-pg_config=DIR	pg_config for PostgreSQL],
[
if test "$withval" != no
then
	PG_CONFIG="$withval"
	if test ! -f "${PG_CONFIG}"
	then
		AC_MSG_ERROR([Could not find your PostgreSQL installation])
	fi
fi
],
[
STANDARD_PREFIXES="/usr /usr/local /opt /local /mingw"
PG_CONFIG=""
for i in `echo "$STANDARD_PREFIXES"`; do
	if test -f "$i/bin/pg_config"; then
		PG_CONFIG="$i/bin/pg_config"
    	break;
    fi
done
])
#AC_CHECK_PROGS([PG_CONFIG], [pg_config], [pg_config], [$PATH:/usr/local/pgsql/bin:/usr/pgsql/bin])
if test x"$PG_CONFIG" = x; then
    AC_MSG_ERROR([$PACKAGE requires pg_config])
fi
AC_SUBST([PG_LIBS],  [`$PG_CONFIG --libdir`])
AC_SUBST([PG_INCLUDE], [`$PG_CONFIG --includedir`])
AC_SUBST([PG_CFLAGS],  ['-I$(PG_INCLUDE)'])
AC_SUBST([PG_CPPFLAGS],  ['-I$(PG_INCLUDE)'])
AC_SUBST([PG_LDFLAGS], ['-L$(PG_LIBS)'])
AC_MSG_CHECKING([PostGreSQL: Identificando modo de compilação: ])
if test "x$with_dinamico" = "xyes"; then
	AC_SUBST([LIBPQ_libs],['-L$(PG_LIBS) -lpq -lssl'])
    AC_MSG_RESULT([Dinâmica])
	break;
else
	AC_SUBST([LIBPQ_libs],['$(PG_LIBS)/libpq.a -lssl'])
	AC_MSG_RESULT([Estática])
fi

AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_LDFLAGS])

AC_HEADER_STDC
AC_CHECK_HEADERS([iostream string string.h fstream vector],,,[AC_INCLUDES_DEFAULT])
AC_CHECK_HEADERS([ctime cstdio cstdlib ctype.h ltdl.h dlfcn.h zlib.h],,,[AC_INCLUDES_DEFAULT])
AC_SEARCH_LIBS([lt_dlopen], [ltdl])
AC_SEARCH_LIBS([dlopen], [dl])

AC_SUBST([LIBBANCOPG_SO_VERSION], [2:0:0])
AC_SUBST([LIBBANCOPG_API_VERSION], [2.0])

AC_DEFINE([DB_TESTE],["../teste/db.conf"],[Arquivo de Configuração Teste])
AH_TOP([
#ifndef __CONFIGBPG_H__
#define __CONFIGBPG_H__ 1

#if  defined(__WIN32__) || defined(__WIN__)
#define NO_LINUX 1
#include <windows.h>
#endif
])
AH_BOTTOM([
#ifdef HAVE_IOSTREAM
# include <iostream>
#endif
#ifdef HAVE_STRING
# include <string>
#endif
#ifdef HAVE_FSTREAM
# include <fstream>
#endif
#ifdef HAVE_VECTOR
# include <vector>
#endif
#ifdef HAVE_CTIME
# include <ctime>
#endif
#ifdef HAVE_CSTDIO
# include <cstdio>
#endif
#ifdef HAVE_CSTDLIB
# include <cstdlib>
#endif
#ifdef HAVE_CTYPE_H
# include <ctype.h>
#endif
#ifdef HAVE_LTDL_H
# include <ltdl.h>
#endif
#ifdef HAVE_DLFCN_H
# include <dlfcn.h>
#endif
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_HPDF_H
# include <hpdf.h>
#endif
#ifdef HAVE_ZLIB_H
# include <zlib.h>
#endif

#endif /*__CONFIGBPG_H__*/
])

AC_CONFIG_FILES([Makefile src/Makefile man/Makefile libbancopg-${LIBBANCOPG_API_VERSION}.pc:libbancopg.pc.in])
AC_OUTPUT
